<?php
namespace app\index\controller;
/**
 *
 * Class Index
 * @package app\index\controller
 */
class Index extends Site
{
    public function index()
    {
        //查询地址
        exit("404");
    }
    public function img(){
        return $this->fetch();
    }
    public function video(){
        return $this->fetch();
    }
    public function file(){
        return $this->fetch();
    }
    private function PutMovie($file) {
        ini_set('memory_limit','512M');
        header("Content-type: video/mp4");
        header("Accept-Ranges: bytes");

        ob_start(); // ------ 开启缓冲区
        $size = filesize($file);

        if(isset($_SERVER['HTTP_RANGE'])){
            header("HTTP/1.1 206 Partial Content");
            list($name, $range) = explode("=", $_SERVER['HTTP_RANGE']);
            list($begin, $end) =explode("-", $range);
            if($end == 0) $end = $size - 1;
        }
        else {
            $begin = 0; $end = $size - 1;
        }

        header("Content-Length: " . ($end - $begin + 1));
        header("Content-Disposition: filename=".basename($file));
        header("Content-Range: bytes ".$begin."-".$end."/".$size);

        try {
            $fp = fopen($file, 'r');
        } catch (\Exception $e) {
            echo $e->getTraceAsString();exit;
        }
        fseek($fp, $begin);
        $contents = '';

        while(!feof($fp)) {
            $p = min(1024, $end - $begin + 1);
            //$begin += $p;
            $contents .= fread($fp, $p);
            //echo fread($fp, $p);
        }
        //$contents = ltrim($contents, "\XEF\XBB\XBF");
        ob_end_clean();            // ------ 清除缓冲区
        ob_clean();
        //$contents = substr($contents, 3);
        fclose($fp);

        exit($contents);
    }
}
